package com.ecloud.common.utils.check;

import java.util.Collection;

/**
 * Collection工具类
 *
 * @author LiuGangQiang Create in 2020/03/07
 */
public class CollectionUtils {
    /**
     * 校验Collection是否为Null或者无数据
     *
     * @author LiuGangQiang Create in 2020/03/07
     * @param collection Collection对象
     * @return {@link Boolean} 是否为Null或者无数据
     */
    public static boolean isEmpty(final Collection<?> collection) {
        return collection == null || collection.size() == 0;
    }

    /**
     * 校验Collection是否不为Null且存在数据
     *
     * @author LiuGangQiang Create in 2020/03/07
     * @param collection Collection对象
     * @return {@link Boolean} 是否不为Null且存在数据
     */
    public static boolean isNotEmpty(final Collection<?> collection) {
        return collection != null && collection.size() > 0;
    }

    /**
     * 校验Collection是否不为空且元素数量大于某个数
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @param target     目标数量
     * @return {@link Boolean}
     */
    public static boolean isGt(final Collection<?> collection, final int target) {
        return collection != null && collection.size() > target;
    }

    /**
     * 校验Collection是否不为空且元素数量大于零
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @return {@link Boolean}
     */
    public static boolean isGtZero(final Collection<?> collection) {
        return isGt(collection, 0);
    }

    /**
     * 校验Collection是否不为空且元素数量大于等于某个数
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @param target     目标数量
     * @return {@link Boolean}
     */
    public static boolean isGe(final Collection<?> collection, final int target) {
        return collection != null && collection.size() >= target;
    }

    /**
     * 校验Collection是否不为空且元素数量大于等于零
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @return {@link Boolean}
     */
    public static boolean isGeZero(final Collection<?> collection) {
        return isGe(collection, 0);
    }

    /**
     * 校验Collection是否不为空且元素数量小于某个数
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @param target     目标数量
     * @return {@link Boolean}
     */
    public static boolean isLt(final Collection<?> collection, final int target) {
        return collection != null && collection.size() < target;
    }

    /**
     * 校验Collection是否不为空且元素数量小于零
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @return {@link Boolean}
     */
    public static boolean isLtZero(final Collection<?> collection) {
        return isLt(collection, 0);
    }

    /**
     * 校验Collection是否不为空且元素数量小于等于某个数
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @param target     目标数量
     * @return {@link Boolean}
     */
    public static boolean isLe(final Collection<?> collection, final int target) {
        return collection != null && collection.size() <= target;
    }

    /**
     * 校验Collection是否不为空且元素数量小于等于零
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @return {@link Boolean}
     */
    public static boolean isLeZero(final Collection<?> collection) {
        return isLe(collection, 0);
    }

    /**
     * 校验Collection是否不为空且元素数量等于某个数
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @param target     目标数量
     * @return {@link Boolean}
     */
    public static boolean isEq(final Collection<?> collection, final int target) {
        return collection != null && collection.size() == target;
    }

    /**
     * 校验Collection是否不为空且元素数量等于零
     *
     * @author LiuGangQiang Create in 2020/06/19
     * @param collection Collection对象
     * @return {@link Boolean}
     */
    public static boolean isEqZero(final Collection<?> collection) {
        return isEq(collection, 0);
    }
}
